import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 * 
 * @author Escalade
 */
public class Controller implements ActionListener, ListSelectionListener {

	private MVC mvc = null;

	/*
	 * Constructor
	 */
	public Controller(MVC mvc) {
		this.mvc = mvc;
	}

	/*
	 * Detect key pressed
	 */
	public void actionPerformed(ActionEvent e) {
		Object source = e.getSource();

		if (source == mvc.getView().okButton) {
			JOptionPane.showMessageDialog(mvc, "OK Button");
		} else if (source == mvc.getView().cancelButton) {
			JOptionPane.showMessageDialog(mvc, "CANCEL Button");
		} else
			System.out.println("ActionPerformed");
	}

	/*
	 * Detect list Item
	 */
	public void valueChanged(ListSelectionEvent e) {
		Object source = e.getSource();

		if (source == mvc.getView().list) {
			JList list = (JList) source;
			JOptionPane.showMessageDialog(mvc,
					"The list item " + list.getSelectedValue()
							+ " was selected");
		}
	}

}